Implementing User Authentication
Table of Contents
Enabling Sessions With Application.cfm (ColdFusion Only)
One of the functions of the Log In User server behavior is that it creates a session variable when the user successfully logs in. The problem is, the session scope is inactive by default in ColdFusion, which means that the login page won't work. You'll have to activate session management in the ColdFusion Web Application Framework. Doing so is a simple matter of creating a new file (Application.cfm), and entering a single line of code.
-
Create a new page in code view. Delete all of the code on the page, including any HTML, XML, or other tags or code.
Application.cfm is not a regular web page, and so it should not have any code on it to begin.
-
Type the following code:
<cfapplication sessionmanagement="yes" setclientcookies="yes" name="user_auth" sessiontimeout="#CreateTimeSpan(0,0, 20, 0)#">
Figure 8. Enabling sessions with the Application.cfm file
The
cfapplicationtag effectively creates an application and enables the web application framework. It has several attributes, many of which are optional. One required attribute isname, which is any name you want to give your application. The other attributes used enable session management, enable the setting of cookies, and create a session timeout.Note that rather than specifying a simple period of time in the
sessiontimeoutattribute, there is a function,CreateTimeSpan(). This function takes four parameters, standing for days, hours, minutes, and seconds. Thus, thesessiontimeoutattribute is set for 20 minutes. In other words, if a user is inactive or leaves the site to browse on other pages for more than 20 minutes, all session variables associated with that user are flushed. In practical terms, it means the user would have to log in again. -
Save, close, and upload Application.cfm.
At this point you can test the registration and login features you've added in this lesson. As mentioned earlier, try to break the application, by entering every variation you can think of.